package com.itheima.organization.controller;

import com.github.pagehelper.Page;
import com.itheima.aom.pojo.AomOrder;
import com.itheima.aom.pojo.AomUser;
import com.itheima.aom.pojo.QueryPageBean;
import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import com.itheima.organization.service.AomUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/aomUser")
public class AomUserController {

    @Autowired
    private AomUserService aomUserService;

    /**
     * 分页查询用户
     * @param serchMap
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findPage/{page}/{size}")
    public Result findPage(@RequestParam Map<String, Object> serchMap, @PathVariable Integer page, @PathVariable Integer size){
        try {
            Page<AomUser> aomUsers = aomUserService.queryAomUser(serchMap, page, size);
            PageResult<AomUser> pageResult = new PageResult<>(aomUsers.getTotal(), aomUsers.getResult());
            return new Result(true, StatusCode.OK, "分页查询用户成功", pageResult);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, StatusCode.ERROR, "分页查询用户失败");
        }
    }

    /**
     * 重置用户密码为123456
     * @param aomUser
     * @return
     */
    @PutMapping("/updatePassword")
    public Result updatePassword(@RequestBody AomUser aomUser){
        try {
            aomUserService.updatePassword(aomUser);
            return new Result(true, StatusCode.OK, "重置用户密码成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, StatusCode.ERROR, "重置用户密码失败");
        }
    }


}
